//
//  C_NewSongPlayerCollectionViewCell.m
//  音悦咖
//
//  Created by Best on 15/7/22.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "C_NewSongPlayerCollectionViewCell.h"

@implementation C_NewSongPlayerCollectionViewCell

- (void)dealloc
{
    [_countImageView release];
    [_countLabel release];
    [_songNameLabel release];
    [_singerLabel release];
    [_otherButton release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}


- (void)create
{
    self.countImageView = [[UIImageView alloc] init];
    [self addSubview:self.countImageView];
    [_countImageView release];
    
    
    self.countLabel = [[UILabel alloc] init];
    [self addSubview:self.countLabel];
    [_countLabel release];
    
    self.songNameLabel = [[UILabel alloc] init];
    [self addSubview:self.songNameLabel];
    [_songNameLabel release];
    
    self.singerLabel = [[UILabel alloc] init];
    [self addSubview:self.singerLabel];
    [_singerLabel release];
    
    self.otherButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self addSubview:self.otherButton];
    self.placeLabel = [[UILabel alloc] init];
    [self addSubview:self.placeLabel];
    [_placeLabel release];
    [self.placeLabel.layer setBorderWidth:1];
    
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.countImageView.frame = CGRectMake(10, 5, 30, 30);
    self.countImageView.image = [UIImage imageWithContentsOfFile:GETBUNDLE_PATH(@"favourite@2x", @"png")];
    self.countLabel.frame = CGRectMake(5, self.countImageView.frame.origin.y + self.countImageView.frame.size.height + 3, 50, 20);
    [self.countLabel setTextAlignment:(NSTextAlignmentCenter)];
    self.countLabel.font = [UIFont systemFontOfSize:13];
    self.songNameLabel.frame = CGRectMake(self.countImageView.frame.size.width + self.countImageView.frame.origin.x + 10, self.countImageView.frame.origin.y, 200, 30);
    self.songNameLabel.font = [UIFont systemFontOfSize:15];
    self.singerLabel.frame = CGRectMake(self.songNameLabel.frame.origin.x + 10, self.songNameLabel.frame.origin.y + self.songNameLabel.frame.size.height + 3, 100, 20);
    self.singerLabel.textColor = RGBA(190, 190, 190, 1);
    self.singerLabel.font = [UIFont systemFontOfSize:15];
    self.otherButton.frame = CGRectMake(layoutAttributes.frame.size.width - 40, 0, 40, layoutAttributes.frame.size.height);
    self.placeLabel.frame = CGRectMake(0, layoutAttributes.frame.size.height - 1, layoutAttributes.frame.size.width, 1);
    
    
}

- (void)setModel:(C_NewSongPlayerModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    self.songNameLabel.text = model.song_name;
    self.singerLabel.text = model.singer_name;
    if ([model.pick_count integerValue] < 10000) {
        self.countLabel.text = [model.pick_count description];
    } else {
        self.countLabel.text = [NSString stringWithFormat:@"%.2f万", [model.pick_count floatValue] / 10000.00];
    }
    
}

@end
